/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package view;


import connectivity.QueryManager;
import java.sql.ResultSet;
import java.util.List;
import javax.swing.JOptionPane;
import main.BarApplication;
import model.Factuur;
import model.Member;

/**
 *
 * @author Mamadou
 */
public class FactuurOverview extends javax.swing.JPanel {

    private ResultSet rs;
    private LoginScreen login;

    /**
     * Creates new form FactuurOverview
     */
    public FactuurOverview(LoginScreen login) {

        initComponents();
        this.login = login;
        tableFactuur();
    }

    //-----------------------------------------------------------------------------
//  Hiermee wordt de tableProduct gelinkt aan de database
//-----------------------------------------------------------------------------
    private void tableFactuur() {

        QueryManager queryManager = BarApplication.getQueryManager();
        jTable_Factuur.setModel(model.DbUtils.resultSetToTableModel(queryManager.MemberList(rs)));
        jTable_Factuur.setAutoCreateRowSorter(true);


    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel40 = new javax.swing.JPanel();
        jButton28 = new javax.swing.JButton();
        jLabel7 = new javax.swing.JLabel();
        jPanel24 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable_Factuur = new javax.swing.JTable()
        {
            public boolean isCellEditable(int rowIndex, int colIndex) {
                return false;
            }
        };
        jPanel5 = new javax.swing.JPanel();
        home = new javax.swing.JLabel();
        leden1 = new javax.swing.JLabel();
        activiteit1 = new javax.swing.JLabel();
        bar1 = new javax.swing.JLabel();
        factuur1 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();

        jPanel40.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        jButton28.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/size32/Devices-printer-icon.png"))); // NOI18N
        jButton28.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton28ActionPerformed(evt);
            }
        });

        jLabel7.setFont(new java.awt.Font("Arial", 0, 36)); // NOI18N
        jLabel7.setForeground(new java.awt.Color(4, 54, 128));
        jLabel7.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/size32/invoice-icon48.png"))); // NOI18N
        jLabel7.setText("Factuur Manager");

        javax.swing.GroupLayout jPanel40Layout = new javax.swing.GroupLayout(jPanel40);
        jPanel40.setLayout(jPanel40Layout);
        jPanel40Layout.setHorizontalGroup(
            jPanel40Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel40Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, 334, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jButton28)
                .addContainerGap())
        );
        jPanel40Layout.setVerticalGroup(
            jPanel40Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel40Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel40Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel7)
                    .addComponent(jButton28))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel24.setBackground(new java.awt.Color(153, 153, 153));
        jPanel24.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));

        javax.swing.GroupLayout jPanel24Layout = new javax.swing.GroupLayout(jPanel24);
        jPanel24.setLayout(jPanel24Layout);
        jPanel24Layout.setHorizontalGroup(
            jPanel24Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 929, Short.MAX_VALUE)
        );
        jPanel24Layout.setVerticalGroup(
            jPanel24Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 41, Short.MAX_VALUE)
        );

        jTable_Factuur.setAutoCreateRowSorter(true);
        jTable_Factuur.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jTable_Factuur.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jTable_FactuurMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(jTable_Factuur);

        home.setText("Home");
        home.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        home.setFocusCycleRoot(true);
        home.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                homeMouseClicked(evt);
            }
        });

        leden1.setText("Leden");
        leden1.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        leden1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                leden1MouseClicked(evt);
            }
        });

        activiteit1.setText("Activiteit");
        activiteit1.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        activiteit1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                activiteit1MouseClicked(evt);
            }
        });

        bar1.setText("Bar");
        bar1.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        bar1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                bar1MouseClicked(evt);
            }
        });

        factuur1.setText("Factuur");
        factuur1.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        factuur1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                factuur1MouseClicked(evt);
            }
        });

        jLabel9.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/size32/Apps-session-logout-icon.png"))); // NOI18N
        jLabel9.setText("logout");
        jLabel9.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jLabel9MouseClicked(evt);
            }
        });

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(home)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(leden1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(activiteit1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(factuur1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(bar1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jLabel9)
                .addContainerGap())
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel5Layout.createSequentialGroup()
                .addContainerGap(20, Short.MAX_VALUE)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(home)
                    .addComponent(leden1)
                    .addComponent(activiteit1)
                    .addComponent(bar1)
                    .addComponent(factuur1))
                .addContainerGap())
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addComponent(jLabel9)
                .addGap(0, 0, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel40, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel24, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jScrollPane1))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(9, 9, 9)
                .addComponent(jPanel40, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel24, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 352, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(15, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void jTable_FactuurMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTable_FactuurMouseClicked

        if (evt.getClickCount() == 2) {
           int row = jTable_Factuur.getSelectedRow();
            String Table_click = (jTable_Factuur.getModel().getValueAt(row, 0).toString());
            int memberId = Integer.parseInt(Table_click);
            System.out.println(memberId);
            Member member = BarApplication.getQueryManager().getMember(memberId);
            BarApplication.getInstance().showPanel(new FactuurDetail(login, member));
            
            
            try {
            } catch (Exception ex) {
                JOptionPane.showMessageDialog(this,
                        "Klik op Factuur",
                        "Factuur", JOptionPane.ERROR_MESSAGE);
            }

        }
    }//GEN-LAST:event_jTable_FactuurMouseClicked

    private void homeMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_homeMouseClicked
        // TODO add your handling code here:
        BarApplication.getInstance().showPanel(new Home(login));
    }//GEN-LAST:event_homeMouseClicked

    private void leden1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_leden1MouseClicked
        BarApplication.getInstance().showPanel(new MemberOverview(login));
    }//GEN-LAST:event_leden1MouseClicked

    private void activiteit1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_activiteit1MouseClicked

        BarApplication.getInstance().showPanel(new GroupActivityOverview(login));


    }//GEN-LAST:event_activiteit1MouseClicked

    private void bar1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_bar1MouseClicked

        if (evt != null) {
            BarApplication.getInstance().showPanel(new shopping_bar(login));
        }
    }//GEN-LAST:event_bar1MouseClicked

    private void factuur1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_factuur1MouseClicked
        if (evt != null) {
            BarApplication.getInstance().showPanel(new FactuurOverview(login));
        }
    }//GEN-LAST:event_factuur1MouseClicked

    private void jButton28ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton28ActionPerformed
        // List<Factuur> facturen = new ArrayList<Factuur>();
    }//GEN-LAST:event_jButton28ActionPerformed

    private void jLabel9MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel9MouseClicked
        // TODO add your handling code here:
        BarApplication.getInstance().showPanel(new LoginScreen());
    }//GEN-LAST:event_jLabel9MouseClicked

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel activiteit1;
    private javax.swing.JLabel bar1;
    private javax.swing.JLabel factuur1;
    private javax.swing.JLabel home;
    private javax.swing.JButton jButton28;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel24;
    private javax.swing.JPanel jPanel40;
    public javax.swing.JPanel jPanel5;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTable_Factuur;
    private javax.swing.JLabel leden1;
    // End of variables declaration//GEN-END:variables
}
